package com.sisy.dubbo_provider;

import com.sisy.common.RefundOrder;
import com.sisy.mapper.RefundOrderMapper;
import io.seata.spring.annotation.GlobalTransactional;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@SpringBootApplication
@MapperScan(basePackages = "com.sisy.mapper")
@ImportResource({
        "classpath:spring/*.xml"
})
@Controller
@ComponentScan({"com.sisy"})
public class DubboProviderApplication {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(DubboProviderApplication.class, args);
    }

    @Autowired
    RefundOrderMapper refundOrderMapper;

    @PostMapping("/create/refund")
    @ResponseBody
    public String createRefund(@RequestBody RefundOrder refundOrder){
        int res = refundOrderMapper.createOrder(refundOrder);
        return String.valueOf(res);
    }

    @GetMapping("/refund/{id}")
    @ResponseBody
    public RefundOrder getRefundOrder(@PathVariable int id){
        RefundOrder refundOrder = refundOrderMapper.selectRefundOrder(id);
        return refundOrder;
    }

    @GetMapping("/refund/for/update/{id}")
    @ResponseBody
    public RefundOrder getRefundOrderForUpdate(@PathVariable int id){
        RefundOrder refundOrder = refundOrderMapper.selectRefundOrderForUpdate(id);
        return refundOrder;
    }
}
